#!/usr/bin/perl -w




use BogoMsg;
use BogoConHandler;

use BogoClientDialogs;

use BogoCommands;
use BogoLogger;

BogoLogger->setlog("mylog.txt", 2);

my $conhndl= BogoConHandler->new();


sub cmdChoice{
	print "\nChoose Command to create response:\n";
	my %cmdlist =  BogoCommands->getCmdsVals('client');
	
	
	while(($key, $val)= each( %cmdlist))
	{
		print "\t".$val." - ".$key."\n";
		
	}
	print "Type number of command:";
	my $choice = -1;
	chomp($choice = <>);
	foreach $key (%cmdlist)
	{
		if(defined($cmdlist{$key}))
		{
			if($choice == $cmdlist{$key})
			{
				return $key;
			}
		}
	}
	return undef;
	
}





sub main{
	BogoLogger->msg(3, "MainRunner", "Bogo Debug Client started!\n");
	
	my $dialoger = BogoCDialogs->new;
	my %setupset = $dialoger->connsetup();

	
	BogoLogger->msg(3,"MainRunner", "Connecting to host: $setupset{'host'}!\n");
	$conhndl->init_connection($setupset{'host'}, $setupset{'port'}, $setupset{'timeout'}, 'tcp');

	BogoLogger->msg(3,"MainRunner", "Connection established\n");


#inloop:
#1 - Show Msg from Server
#1.1 - Print Header and content of msg
#2 - Collect response to Server
#2.1 - List of Commands to send to server
#2.2 - run sub menu by user selection

	AGAIN: while(1)
	{
		
		my $resp = $conhndl->recvDT;
		print $resp;
		print "Received from server:\n";
	
		my $res = &cmdChoice();
		print $res."\n";
		if(!defined($res))
		{
			print "Error! Select again!\n";
			next AGAIN;
		}
		my $newmsg = $dialoger->createMsg($res);
		$newmsg->printHeader();
		$conhndl->sendDT($newmsg->marshall());
		
		exit;

	}
	$conhndl->sendDT("exit");

}


&main();

